/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * @author ZhangMaoren 
 * @since 2015年4月27日
 * @version 0.1
 */
package com.suredy.security.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.suredy.core.model.BaseModel;
import com.suredy.security.model.User2Role;


/**
 * @author ZhangMaoren
 *
 */
@Entity
@Table(name = "T_SECURITY_USER2ROLE")
public class User2RoleEntity extends BaseModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1353714858463404223L;

	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "USERID")
	private UserEntity user;
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "ROLEID")
	private RoleEntity role;
	
	


	
	
	/**
	 * @return the user
	 */
	public UserEntity getUser() {
		return user;
	}





	
	/**
	 * @param user the user to set
	 */
	public void setUser(UserEntity user) {
		this.user = user;
	}





	
	/**
	 * @return the role
	 */
	public RoleEntity getRole() {
		return role;
	}





	
	/**
	 * @param role the role to set
	 */
	public void setRole(RoleEntity role) {
		this.role = role;
	}




	@Transient
	public User2Role toVO(){
		User2Role vo = new User2Role();
		vo.setId(id);
		vo.setRoleId(role.getId());
		vo.setUserId(user.getId());
		vo.setRoleCode(role.getCode());
		return vo;
	}
}
